package com.property.manage.controller.parking;

import com.guardchina.framework.mybatis.model.CustomPage;
import com.property.manage.model.parking.ParkingVo;
import com.property.manage.model.system.SysSet;
import com.property.manage.model.village.DownVo;
import com.property.manage.model.village.Village;
import com.property.manage.service.parking.ParkingService;
import com.property.manage.service.system.SysSetService;
import com.property.manage.service.village.VillageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;

/**
 * 描述
 *
 * @author lwb
 * @since 2020/7/15
 */
@Api(tags = "车位管理")
@RestController
@RequestMapping("/parking")
@AllArgsConstructor
@Validated
public class ParkingController {

   @Autowired
   private ParkingService parkingService;


    @ApiOperation("车位列表")
    @GetMapping("/page")
    public CustomPage<ParkingVo> userPage(@ApiParam("当前页码") @RequestParam("pageNo") @NotNull(message = "请输入当前页码") Long pageNo,
                                          @ApiParam("每页条数") @RequestParam("pageSize") @NotNull(message = "请输入每页条数") Long pageSize,
                                          @ApiParam("小区id") @RequestParam(value = "villageId", required = false) Integer villageId,
                                          @ApiParam("车位编号") @RequestParam(value = "number", required = false) String number,
                                          @ApiParam("车牌") @RequestParam(value = "licensePlate", required = false)String licensePlate,
                                          @ApiParam("类型") @RequestParam(value = "type", required = false)Integer type){
        return parkingService.page(pageNo,pageSize,villageId,number,licensePlate,type);
    }

    @ApiOperation("添加")
    @PostMapping("/add")
    public void add( @ApiParam("小区id") @RequestParam(value = "villageId")@NotNull(message = "小区id不能为空") Integer villageId,
                     @ApiParam("车位编号") @RequestParam(value = "number")@NotNull(message = "车位编号不能为空") String number,
                     @ApiParam("车牌") @RequestParam(value = "licensePlate", required = false)String licensePlate,
                     @ApiParam("类型") @RequestParam(value = "type")@NotNull(message = "类型不能为空")Integer type,
                     @ApiParam("联系方式") @RequestParam(value = "phone", required = false)String phone,
                     @ApiParam("联系人") @RequestParam(value = "userName", required = false)String userName,
                     @ApiParam("金额") @RequestParam(value = "money", required = false)BigDecimal money

    ){
      parkingService.add(type,number,phone,villageId,licensePlate,userName,money);
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public void update(@RequestParam(value = "id")@NotNull(message = "id不能为空") Integer id,
                       @ApiParam("车位编号") @RequestParam(value = "number")@NotNull(message = "车位编号不能为空") String number,
                       @ApiParam("车牌") @RequestParam(value = "licensePlate", required = false)String licensePlate,
                       @ApiParam("类型") @RequestParam(value = "type")@NotNull(message = "类型不能为空")Integer type,
                       @ApiParam("联系方式") @RequestParam(value = "phone", required = false)String phone,
                       @ApiParam("联系人") @RequestParam(value = "userName", required = false)String userName,
                       @ApiParam("金额") @RequestParam(value = "money", required = false)BigDecimal money){
       parkingService.update(id,type,number,phone,licensePlate,userName,money);
    }

    @ApiOperation("删除")
    @PostMapping("/delete")
    public void delete(@ApiParam("车位id") @RequestParam("id") @NotNull(message = "车位id为空") Integer id){
        parkingService.delete(id);
    }
    @ApiOperation("统计车辆")
    @GetMapping("/getCount")
    public Integer getCount(@ApiParam("小区id") @RequestParam(value = "villageId",required = false) Integer villageId){
        return parkingService.getCount(villageId);
    }
}
